import requests,json


def fanyi():
    while True:
        context = input("请输入翻译的内容(退出q)：")

        if context in ['q', 'Q']:
            break
        else:
            url = 'https://fanyi.baidu.com/sug'
            data = {
                "kw":context
            }
            headers = {
                'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'}
            response = requests.post(url, data, headers=headers)
            #result=json.loads(response.text)
            print(response.json()['data'][0]['v'])
            #print(result['data'][0]['v'])


fanyi()

